package com.gupaoedu.vip.factory.homework.simplefactory;

import com.gupaoedu.vip.factory.homework.AudiCar;
import com.gupaoedu.vip.factory.homework.BMWCar;
import com.gupaoedu.vip.factory.homework.BenzCar;
import com.gupaoedu.vip.factory.homework.Car;

/**
 * @Auther: tcm
 * @Date: 2020/1/14 14:13
 * @Description:
 */
public class CarFactory implements ICarFactory {


    @Override
    public Car createCar(String carName) {
        if(carName.equals("奥迪")){
            return new AudiCar();
        }else if(carName.equals("奔驰")){
            return new BenzCar();
        }else if(carName.equals("宝马")){
            return new BMWCar();
        }
        return null;
    }

    @Override
    public Car createCar(Class<?> clazz) {
        try {
            return (Car)clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
